package com.ebelter.temperature.activitys;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.RelativeLayout;

import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.common.Constants;
import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.beans.ScaleUser;
import com.ebelter.btcomlib.models.bluetooth.products.temperature.TemperatureBytesMakeFatory;
import com.ebelter.btcomlib.models.excel.ExcelUtils;
import com.ebelter.btcomlib.models.https.NetUtils;
import com.ebelter.btcomlib.models.https.interfaces.HttpResponse;
import com.ebelter.btcomlib.models.https.responses.GetTempertureData;
import com.ebelter.btcomlib.models.https.responses.GetTempertureData2;
import com.ebelter.btcomlib.models.https.responses.LoginResponse;
import com.ebelter.btcomlib.utils.CommonUtils;
import com.ebelter.btcomlib.utils.FileUtils;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.StatusBarUtil;
import com.ebelter.btcomlib.utils.ThreadManager;
import com.ebelter.btcomlib.utils.TimeUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.btcomlib.views.ChartView2;
import com.ebelter.temperature.R;
import com.ebelter.temperature.models.T_WarringModelUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class T_CeshiActivity extends BaseActivity {


    private static final String TAG = "T_CeshiActivity";
//    private WaveHelper mWaveHelper;
//    private WaveView mWaveView;
//    private int mBorderColor = Color.parseColor("#ebebeb");
//    private int mBorderWidth = 0;
   // private RelativeLayout wave_waihuan_rl;


    private static final String time1 = "2018-08-08 08:08:08";
    private static final String time2 = "2018-08-08 08:08:09";
    private static final String time3 = "2018-08-08 08:08:10";
    private static final String time4 = "2018-08-08 08:08:12";
    private static final String time5 = "2018-08-08 08:08:15";
    private static final String time6 = "2018-08-08 08:08:30";
    private static final String time7 = "2018-08-08 08:08:48";
    private static final String time8 = "2018-08-08 08:08:58";
    private static final String time9 = "2018-08-08 08:09:08";
    private static final String time10 = "2018-08-08 08:09:18";
    private static final String time11 = "2018-08-08 08:18:08";
    private static final String time12 = "2018-08-08 08:28:08";
    private static final String time13 = "2018-08-08 08:38:08";
    private static final String time14 = "2018-08-08 08:48:08";
    private static final String time15 = "2018-08-08 08:58:08";
    private static final String time16 = "2018-08-08 09:08:08";
    private static final String time17 = "2018-08-08 10:08:08";
    private static final String time18 = "2018-08-08 11:08:08";
    private static final String time19 = "2018-08-08 14:08:08";
    private static final String time20 = "2018-08-08 16:08:08";


    private ChartView2 chartview2;

    private T_WarringModelUtils t_warringModelUtils;

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_t_ceshi;
    }

    @Override
    protected void initView() {
        StatusBarUtil.setDarkStatusIcon(this,true);
        makeFatory=new TemperatureBytesMakeFatory();
        FV();
        t_warringModelUtils=new T_WarringModelUtils(getApplicationContext());
        //mWaveHelper=new WaveHelper(mWaveView);

    }

    private void FV() {
//        mWaveView = (WaveView) findViewById(R.id.wave);
//        mWaveView.setBorder(mBorderWidth, mBorderColor);
//        mWaveView.setShapeType(WaveView.ShapeType.CIRCLE);
//        mWaveView.setWaveColor(
//                Color.parseColor("#878de1"),
//                Color.parseColor("#7f83de"));
//        mBorderColor = Color.parseColor("#b8f1ed");
//        mWaveView.setBorder(mBorderWidth, mBorderColor);


     //   wave_waihuan_rl=findViewById(R.id.wave_waihuan_rl);
        chartview2=findViewById(R.id.chartview2);
    }

    @Override
    protected void onPause() {
        super.onPause();
       // mWaveHelper.cancel();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //mWaveHelper.start();
    }

    private ObjectAnimator ra;
    //登录按钮
    @SuppressLint("WrongConstant")
    public void AClick(View view){

        LogUtils.i(TAG,"--------------A-------------");

       // mWaveHelper.progress(0.3f);
       // wave_waihuan_rl.setRotation(wave_waihuan_rl.getRotation()+3);


//        ra = ObjectAnimator.ofFloat(wave_waihuan_rl,"rotation", 0f, 360f);
//        ra.setDuration(3000);
//        //ra.setRepeatMode(Animation.INFINITE);
//        ra.setRepeatCount(-1);
//        LinearInterpolator lin = new LinearInterpolator();//设置动画匀速运动
//        ra.setInterpolator(lin);
//        ra.start();

        initChartView2Datas();
    }

    //初始化数据
    private void initChartView2Datas() {
        //x轴坐标对应的数据
        List<String> oneXValue = new ArrayList<>();

        //y轴坐标对应的数据
        List<Float> oneYValue = new ArrayList<>();

        //折线对应的数据
        Map<String, Float> oneValue = new HashMap<>();

        for (int i = 0; i < 4; i++) {//Y轴的刻度值
            oneYValue.add(i *15f);
        }


        //2018-08-08 08:08:08

        oneXValue.add(time1);
        oneValue.put(time1, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time2);
        oneValue.put(time2, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time3);
        oneValue.put(time3, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time4);
        oneValue.put(time4, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time5);
        oneValue.put(time5, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time6);
        oneValue.put(time6, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time7);
        oneValue.put(time7, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time9);
        oneValue.put(time9, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time10);
        oneValue.put(time10, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time11);
        oneValue.put(time11, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time12);
        oneValue.put(time12, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time13);
        oneValue.put(time13, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time14);
        oneValue.put(time14, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time15);
        oneValue.put(time15, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time16);
        oneValue.put(time16, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time17);
        oneValue.put(time17, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time18);
        oneValue.put(time18, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time19);
        oneValue.put(time19, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        oneXValue.add(time20);
        oneValue.put(time20, NumUtils.numBaoLiuWei1(NumUtils.randomF(35.1f,42.2f)));

        if (chartview2!=null){
            chartview2.isDisplayXDateFlag = false;
            chartview2.setValue(oneValue,oneXValue,oneYValue);
        }


    }

    private TemperatureBytesMakeFatory makeFatory;

    List<Float> ce=new ArrayList<>();
    public void BClick(View view){

        LogUtils.i(TAG,"--------------B-------------");
      //  makeFatory.getSyncSystemClock();
//        ra.pause();
        t_warringModelUtils.vibrationRemind();
      //  get2HData();
       // chartview2.addXValue(TimeUtils.getCurrentTime1(),38.3f);

    }

    private ExcelUtils mExcelUtils=new ExcelUtils();

    private static final String[] col=new String[]{"NO","name","age","sex"};
    public void CClick(View view){

        LogUtils.i(TAG,"--------------C-------------");

        final List<CeShiBean> datas=new ArrayList<>();
        for (int i=0;i<10;i++){
            CeShiBean bean=new CeShiBean();
            bean.NO=i+"";
            bean.name=i+"name";
            bean.age=i+"age";
            bean.sex=i+"sex";
            datas.add(bean);
        }


        ThreadManager.getShortPool().execute(new Runnable() {
            @Override
            public void run() {

                File file=new File(FileUtils.getSDPath()+"/1Test2/text.xls");
                mExcelUtils.outExcelData(file, datas, col, new IOrder() {
                    @Override
                    public void cmd(int cmd, Object... objects) {
                        LogUtils.i(TAG,"---cmd = "+cmd);
                    }
                });
            }
        });






    }


    //获取2个小时的数据
    private void get2HData() {
        String testDate = TimeUtils.getCurrentTime1();
        LogUtils.i(TAG,"------------get2HData()--testDate = "+testDate);


        NetUtils.getInstance().getData_T(this, testDate, new HttpResponse<GetTempertureData2>() {
            @Override
            public void result(boolean isRequestSuccess, String requestDes, GetTempertureData2 getTempertureData2, String s) {
                LogUtils.i(TAG,"----------- s = "+s);
                if (!isRequestSuccess){
                    return;
                }
                LogUtils.i(TAG,"----get2HData---"+getTempertureData2.toString());

                if (getTempertureData2.getResultCode()==0){//说明请求成功
                    // disCharView(getTempertureData);
                    LogUtils.i(TAG,"----------- getTempertureData2 = "+getTempertureData2.toString());
                }
            }
        });


    }




    class CeShiBean{
        String name;
        String age;
        String sex;
        String NO;

        public String getNO() {
            return NO;
        }

        public void setNO(String NO) {
            this.NO = NO;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }
    }

}
